home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C & C++ Multimedia Cyber Classroom
/
C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso
/
cpphtp2
/
code.jar
/
code
/
ch14
/
fig14_11.txt
< prev
next >
Wrap
Text File
|
1998-02-27
|
1KB
|
41 lines
1 // Fig. 14.11: clntdata.h
2 // Definition of struct clientData used in
3 // Figs. 14.11, 14.12, 14.14 and 14.15.
4 #ifndef CLNTDATA_H
5 #define CLNTDATA_H
6
7 struct clientData {
8 int accountNumber;
9 char lastName[ 15 ];
10 char firstName[ 10 ];
11 float balance;
12 };
13
14 #endif
15
16
17 // Fig. 14.11: fig14_11.cpp
18 // Creating a randomly accessed file sequentially
19 #include <iostream.h>
20 #include <fstream.h>
21 #include <stdlib.h>
22 #include "clntdata.h"
23
24 int main()
25 {
26 ofstream outCredit( "credit.dat", ios::out );
27
28 if ( !outCredit ) {
29 cerr << "File could not be opened." << endl;
30 exit( 1 );
31 }
32
33 clientData blankClient = { 0, "", "", 0.0 };
34
35 for ( int i = 0; i < 100; i++ )
36 outCredit.write(
37 reinterpret_cast<const char *>( &blankClient ),
38 sizeof( clientData ) );
39 return 0;
40 }